#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <functional>

void printV(vector<int> &v)
{
        for (int i = 0; i < (int)v.size(); i++)
        {
                cout<<v[i] <<" ";
        }
        cout<<endl;
}

template <typename T>
class ShowElement
{
public:
        ShowElement()
        {
                n = 0;
        }
        void operator()(T &t)
        {
                cout<<t;
        }
        void printN()
        {
                n++;
                cout<<"n: "<<n<<endl;
        }
private:
        int n;
};

void test1()
{
        vector<int> v1, v2, v3;
        v1.push_back(1);
        v1.push_back(3);
        v1.push_back(5);
        v2.push_back(2);
        v2.push_back(4);
        v2.push_back(6);

        v3.resize(v1.size() + v2.size());

        merge(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin());

        printV(v3);
}

class Student
{
public:
        friend ostream& operator<<(ostream &out, Student &s)
        {
                out<<"name : "<< s.m_name<<" id = "<< s.m_id<<endl;  
                return out;
        }
public:
        Student(string name, int id)
        {
                m_name = name;
                m_id = id;
        }
public:
        string m_name;
        int m_id;
};

bool CompareS(Student &s1, Student &s2)
{
        return (s1.m_id < s2.m_id) ;
}

void test2()
{
        Student s1("老大", 1);
        Student s2("老二", 2);
        Student s3("老三", 3);
        Student s4("老四", 4);
        Student s5("老五", 5);

        vector<Student> v1;
        v1.push_back(s4);
        v1.push_back(s1);
        v1.push_back(s3);
        v1.push_back(s2);
        v1.push_back(s5);

        for_each(v1.begin(), v1.end(), ShowElement<Student>());

        //sort 根据自定义函数对象 进行自定义数据排序
        //替换 算法的统一性(实现的算法和数据类型的分离) ===》技术手段函数对象
        sort(v1.begin(), v1.end(), CompareS);
        cout<<endl;

        for_each(v1.begin(), v1.end(), ShowElement<Student>());        
}

void test3()
{
        vector<int> v1;
        v1.push_back(1);
        v1.push_back(3);
        v1.push_back(5);
        v1.push_back(7);
        v1.push_back(9);

        random_shuffle(v1.begin(), v1.end());
        printV(v1); 

        string str = "abcdefg";
        random_shuffle(str.begin(), str.end());
        cout<<str<<endl;
}


void test4()
{
        vector<int> v1;
        v1.push_back(1);
        v1.push_back(3);
        v1.push_back(5);
        v1.push_back(7);
        v1.push_back(9);

        reverse(v1.begin(), v1.end());
        printV(v1);
}

int main(int argc, char const *argv[])
{
        //test1();
        //test2();
       // test3();
        test4();
        return 0;
}
